app_family.controller("controller_datadailyconsum", function($scope, $rootScope, httpRequest, $location) {
	$rootScope.$broadcast('currentModule', 'controller_datadailyconsum');
	$rootScope.$broadcast('footerFlag', false); // 是否显示底部导航
	$scope.imagebasepath = imagebasepath;
	data_sessionStorage = JSON.parse(sessionStorage.getItem('data_sessionStorage'));
	
	/**
	 * 判断是否用手机登录过
	 */
	if (sessionStorage.getItem('data_sessionStorage')) {
		var familyPhone = data_sessionStorage.familyInfo.phone;
		if (familyPhone == '' || familyPhone == null) {
			window.location.replace(basepath + 'login.html');
			return;
		}
	} else {
		window.location.replace(basepath + 'login.html');
		return;
	}
	
	$scope.older_account = data_sessionStorage.data_searchFamilyInfo.older_account; // 账号
	/**
	 * 根据账号，查询个人信息
	 */ 
	httpRequest.getOlderInfo({
		account : $scope.older_account
	}, function (data) {
		if (data.success === true) {
			$scope.olderInfoObj = data.obj;
		} else if (data.success === false) {
			$.dialog.showToast({msgTxt : data.msg});
		}
	});
	
	/**
	 * 根据账号，查询账户信息
	 */
	$scope.findOlderAccount = function (account, date) {
		httpRequest.findOlderAccount({
			account : account
		}, function (data) {
			if (data.success === true) {
				$scope.olderAccountObj = data.obj.olderAccount;
			} else if (data.success === false) {
				$.dialog.showToast({msgTxt : data.msg});
			}
		});
	};
	
	/**
	 * 根据账号、起止时间，查询每日消费明细
	 */
	$scope.getOlderBills = function (account, date, dateEnd) {
		httpRequest.getOlderBills({
			account : account,
			timeFrom : date + ' 00:00:00',
			timeTo : dateEnd + ' 23:59:59'
		}, function (data) {
			if (data.success === true) {
				$scope.orderBillList = data.obj.jsonArray;
			} else if (data.success === false) {
				$.dialog.showToast({msgTxt : data.msg});
			}
		});
	};
	
	/**
	 * 页面初始化 
	 */
	$scope.older_account = data_sessionStorage.data_searchFamilyInfo.older_account; // 账号
	var d = new Date(new Date()-168*60*60*1000);
	$scope.date = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
	var endDate = new Date(new Date()-24*60*60*1000);
	$scope.dateEnd = endDate.getFullYear() + '-' + (endDate.getMonth() + 1) + '-' + endDate.getDate();
	
	// 根据账号，查询账户信息
	$scope.findOlderAccount($scope.older_account);
	// 根据账号、起止时间，查询每日消费明细
	$scope.getOlderBills($scope.older_account, $scope.date, $scope.dateEnd);
	
	
	/**
	 * 检索日期控件
	 */
	$('#dateSearch').mobiscroll().calendar({
        theme: 'mobiscroll',  
        lang: 'zh', 
        display: 'bottom',   
        controls: ['date'],
        dateFormat : 'yy-mm-dd',
        maxDate : new Date(),
        minDate : new Date(new Date()-720*60*60*1000),
        layout : 'fixed',
        setText: '确定',
        cancelText: '取消',
        onBeforeShow: function (inst) {
        	
        },
        onSelect: function (valueText, inst) {
        	var older_account = data_sessionStorage.data_searchFamilyInfo.older_account; // 账号
        	$scope.getOlderBills($scope.older_account, valueText, $scope.dateEnd);
        },
        onCancel : function (valueText, inst) {
        	
        }
	});
	
	$('#dateSearchEnd').mobiscroll().calendar({
        theme: 'mobiscroll',  
        lang: 'zh', 
        display: 'bottom',   
        controls: ['date'],
        dateFormat : 'yy-mm-dd',
        maxDate : new Date(),
        minDate : new Date(new Date()-720*60*60*1000),
        layout : 'fixed',
        setText: '确定',
        cancelText: '取消',
        onBeforeShow: function (inst) {
        	
        },
        onSelect: function (valueText, inst) {
        	var older_account = data_sessionStorage.data_searchFamilyInfo.older_account; // 账号
        	$scope.getOlderBills($scope.older_account, $scope.date, valueText);
        },
        onCancel : function (valueText, inst) {
        	
        }
	});
	
});